# -*- coding:utf-8 -*-
import time
from socket import *
import threading
#http://192.168.129.31:8001/
HOST = '220.181.111.148'
HOST = '127.0.0.1'
#HOST = '192.168.129.31'
PORT = 9999
BUFSIZ = 1024
ADDR = (HOST, PORT)

#for i in range(1):

is_continue = True

def main():
    THREAD_AMOUNT = 1
    threads = []
    for i in range(THREAD_AMOUNT):
        t = threading.Thread(target=httpThread, args=(i,))
        threads.append(t)
    for i in range(THREAD_AMOUNT): # start threads
        threads[i].start()
    #raw_input('input: ')
    for i in range(THREAD_AMOUNT): # start threads
        threads[i].join()
    is_continue = False
    
def httpThread(i):
    #print i
    sockets = []
    for ii in range(20): 
        try:
            print ii
            ts=socket(AF_INET,SOCK_STREAM)
            #ts.bind((HOST, 59363))
            ts.connect(ADDR)
            print 'connect'
            headers='''GET / HTTP/1.1
            Referer: http://www.baidu.com/

            '''
            ts.send(str(i)+'''aa\r\n ''')
            print 'send'
            #data=ts.recv(BUFSIZ)
            print data
            sockets.append(ts)
        except Exception,e:
            #print e
            pass
    time.sleep(5)
    for s in sockets:
        print s
        s.close()
if __name__=='__main__':
    main()
print 'end'



